import base64
import httpx
from langchain_core.messages import HumanMessage
from langChain.config import model

image_url_1 = "https://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=https%3A%2F%2Fvcg02.cfp.cn%2Fcreative%2Fvcg%2Fnowater800%2Fnew%2FVCG21gic7747641.jpg&thumburl=https%3A%2F%2Fimg0.baidu.com%2Fit%2Fu%3D2185118828%2C1527000605%26fm%3D253%26fmt%3Dauto%26app%3D138%26f%3DJPEG%3Fw%3D500%26h%3D750"
image_url_2 = "https://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=https%3A%2F%2Fvcg02.cfp.cn%2Fcreative%2Fvcg%2Fnowater800%2Fnew%2FVCG21gic7747641.jpg&thumburl=https%3A%2F%2Fimg0.baidu.com%2Fit%2Fu%3D2185118828%2C1527000605%26fm%3D253%26fmt%3Dauto%26app%3D138%26f%3DJPEG%3Fw%3D500%26h%3D750"
image_data_1 = base64.b64encode(httpx.get(image_url_1).content).decode("utf-8")
message = HumanMessage(
    content=[
        {"type": "text", "text": "用中文描述这张图片中的天气"},
        # 如果图片地址是大模型访问不到，因为网络问题
        # {"type": "image_url", "image_url": {"url": image_url_1}},
        {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_data_1}"}},
    ],
)
response = model.invoke([message])
print(response.content)
print("-------------------------------------------------------------------------------------------")

message_2 = HumanMessage(
    content=[
        {"type": "text", "text": "这两张图片是一样的吗？"},
        {"type": "image_url", "image_url": {"url": image_url_1}},
        {"type": "image_url", "image_url": {"url": image_url_2}},
    ],
)
response = model.invoke([message])
print(response.content)
